package com.dmall.play.interview.chapter08;

import java.util.ArrayList;
import java.util.List;

public class Leetcode17 {

    private final static String[] LETTER_MAP = new String[] {
        " ",
        "",
        "abc",
        "def",
        "ghi",
        "jkl",
        "mno",
        "pqrs",
        "tuv",
        "wxyz"
    };

    private final List<String> res = new ArrayList<>();

    public List<String> letterCombinations(String digits) {
        if (digits == null || "".equalsIgnoreCase(digits)) {
            return res;
        }
        findCombinations(digits, 0, "");
        return res;
    }

    private void findCombinations(String digits, int index, String digit) {
        if (index == digits.length()) {
            res.add(digit);
            return;
        }
        char c = digits.charAt(index);
        String letters = LETTER_MAP[c - '0'];
        for (int i = 0; i < letters.length(); i++) {
            findCombinations(digits, index + 1, digit + letters.charAt(i));
        }
    }

    public static void main(String[] args) {
        Leetcode17 leetcode17 = new Leetcode17();
        System.out.println(leetcode17.letterCombinations("23"));
    }
}
